home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / info-service / gopher / Unix / GopherTools / tstb / tb < prev    next >
Encoding:
Text File  |  1992-10-14  |  2.5 KB  |  102 lines

  1. #!/usr/local/bin/perl
  2. # tb, boone, 07/27/92
  3. # Create an index of all files in a tree
  4. # Copyright (C) 1992, Trustees of Michigan State University
  5. #
  6. # Modifications:
  7. # 07/27/92 Boone      Initial coding
  8. # 09/10/92 Boone      Solved the problem of inserting the current path
  9. #                     into a deliberately empty selector.  This was
  10. #                     causing odd behavior on telnet items, and also
  11. #                     helped ts to lose some items.
  12. # End Modifications
  13. #
  14. # Version 1.2
  15. #
  16. # Description:
  17. # Tb treewalks the current directory, generating Gopher- style
  18. # directories of each one.  The resulting directories are edited for
  19. # completeness (full pathname) and appended to a large listing file.
  20. # This file can be searched with the companion program ts.  Tb uses the
  21. # gopherls program (a symbolic link to gopherd) to generate the basic
  22. # listing.  There are two possible problems with gopherls:
  23. #
  24. #   1. gopherls versions earlier than 1.02 try to write to stdin.  This
  25. #      should be fixed in 1.02.  To fix this in earlier versions, locate
  26. #      the following code in gopherd.c near line 255:
  27. #
  28. #    listdir(0, "/");
  29. #
  30. #      and change it to:
  31. #
  32. #    listdir(fileno(stdout), "/");
  33. #
  34. #   2. gopherls versions earlier than 1.02 set the hostname to a null string.
  35. #      This results in unusable output from tb.  To correct this problem,
  36. #      locate the following code in gopherd.c near line 255:
  37. #
  38. #    if (RunLS) {
  39. #        Zehostname ="";
  40. #        Caching = FALSE;
  41. #
  42. #      and change it to:
  43. #
  44. #    if (RunLS) {
  45. #        Zehostname = GetDNSname(DOMAIN_NAME);
  46. #        Caching = FALSE;
  47. # End Description
  48.  
  49. sub dive
  50. {
  51.     local($dir) = @_;
  52.     local($i, $temp);
  53.     &listit($dir);
  54.     opendir(F, $dir) || die "Unable to open $dir\n";
  55.     local(@flist) = readdir(F);
  56.     close(F);
  57.     foreach $i (@flist)
  58.     {
  59.         next if ($i =~ /^\./);
  60.         $temp = "$dir/$i";
  61.         if (-d $temp)
  62.         {
  63.             &dive($temp);
  64.         }
  65.     }
  66.     return;
  67. }
  68.  
  69. sub listit
  70. {
  71.     local($pathnm) = @_;
  72.     local($j);
  73.     $pathnmsub = $pathnm;
  74.     $pathnmsub =~ s/ /\\ /g;
  75.     open(LS, "/usr/local/etc/gopherls $pathnmsub |");
  76.     local(@lines) = <LS>;
  77.     close(LS);
  78.     foreach $j (@lines)
  79.     {
  80.         chop($j); chop($j);
  81.         next if ($j =~ /^\.$/);
  82.         local(@fields) = split(/\t/, $j);
  83.         if (substr($fields[1], 0, 1) ne "8")
  84.         {
  85.             if (substr($fields[1], 1, 1) eq "/")
  86.             {
  87.                 $fields[1] = substr($fields[1], 0, 1) . 
  88.                     $pathnm . substr($fields[1], 1);
  89.             }
  90.         }
  91.         print LOG join("\t", @fields), "\r\n";
  92.         undef(@fields);
  93.     }
  94.     return;
  95. }
  96.  
  97. open(LOG, ">.ts/.tsdata") || die "Unable to open .tsdata\n";
  98. chdir($ARGV[0]);
  99. &dive(".");
  100. close(LOG);
  101. exit(0);
  102.